generator client {
  provider = "prisma-client-js"
  output   = "../node_modules/.prisma/client"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  userId          Int             @id @default(autoincrement()) @map("user_id")
  name            String          @default("") @map("user_name")
  email           String          @unique @default("") @map("user_mail")
  avatar          String?         @default("") @map("user_avatar")
  gender          String          @default("") @map("user_gender")
  birthDate       DateTime?       @map("birth_date")
  role            String          @default("") @map("user_role")
  description     String?         @default("")
  location        String          @default("")
  createdAt       DateTime        @default(now()) @map("created_at")
  updatedAt       DateTime        @updatedAt @map("updated_at")
  level           String          @default("") @map("user_level")
  typesOfTraining String[]        @map("types_of_traning")
  passwordHash    String          @default("") @map("password_hash")
  client          Client?
  trainer         Trainer?
  orders          Order[]
  personalOrders  PersonalOrder[]
  token           Token[]
  balance         Balance[]
  friends         Friend[]

  @@map("users")
}

model Client {
  id                    Int     @id @default(autoincrement())
  user                  User    @relation(fields: [userId], references: [userId], onDelete: Cascade)
  userId                Int     @unique @map("user_id")
  timeOfTraining        String  @default("") @map("time_of_training")
  caloryLosingPlanTotal Int     @default(0) @map("calory_losing_plan_total")
  caloryLosingPlanDaily Int     @default(0) @map("calory_losing_plan_daily")
  isReady               Boolean @default(false) @map("is_ready")

  @@map("clients")
}

model Trainer {
  id                 Int      @id @default(autoincrement())
  user               User     @relation(fields: [userId], references: [userId], onDelete: Cascade)
  userId             Int      @unique @map("user_id")
  merits             String   @default("")
  isPersonalTraining Boolean? @default(false) @map("personal_training")
  certificate        String[]

  @@map("trainers")
}

model Token {
  id        Int      @id @default(autoincrement())
  tokenId   String   @unique
  userId    Int      @map("user_id")
  exp       DateTime @map("expires_in")
  user      User     @relation(fields: [userId], references: [userId], onDelete: Cascade)
  createdAt DateTime @default(now()) @map("created_at")

  @@map("tokens")
}

model Training {
  id                Int        @id @default(autoincrement())
  title             String     @default("")
  backgroundPicture String     @default("") @map("backgraund_picture")
  levelOfUser       String     @default("") @map("level_of_user")
  typeOfTraining    String     @default("") @map("type_of_training")
  duration          String     @default("")
  price             Int        @default(0)
  caloriesQtt       Int        @default(0) @map("calories_qtt")
  description       String     @default("")
  createdAt         DateTime   @default(now()) @map("created_at")
  gender            String     @default("") @map("gender")
  video             String     @default("")
  rating            Float      @default(0)
  trainerId         Int        @map("trainer_id")
  isPromo           Boolean    @default(false) @map("is_promo")
  feedbacks         Feedback[]

  @@map("trainings")
}

model Feedback {
  id         Int      @id @default(autoincrement())
  userId     Int      @map("user_id")
  training   Training @relation(fields: [trainingId], references: [id], onDelete: Cascade)
  trainingId Int      @map("training_id")
  rating     Int      @default(0)
  text       String   @default("")
  userName   String   @default("") @map("user_name")
  userAvatar String   @default("") @map("user_avatar")
  createdAt  DateTime @default(now()) @map("created_at")

  @@map("feed_backs")
}

model Balance {
  id          Int  @id @default(autoincrement())
  userId      Int  @map("user_id")
  trainingId  Int  @map("training_id")
  trainingQtt Int  @map("training_qtt")
  user        User @relation(fields: [userId], references: [userId], onDelete: Cascade)

  @@map("user_balances")
}

model Order {
  id            Int      @id @default(autoincrement())
  userId        Int      @map("user_id")
  type          String   @default("")
  trainerId     Int      @map("trainer_id")
  trainingId    Int      @map("training_id")
  price         Int      @default(0)
  quantity      Int      @default(0)
  sumPrice      Int      @default(0) @map("sum_price")
  typeOfPayment String   @default("")
  createdAt     DateTime @default(now()) @map("created_at")
  user          User     @relation(fields: [userId], references: [userId], onDelete: Cascade)

  @@map("orders")
}

model PersonalOrder {
  id          Int      @id @default(autoincrement())
  userId      Int      @map("user_id")
  targetId   Int      @map("target_id")
  createdAt   DateTime @default(now()) @map("created_at")
  updateAt    DateTime @default(now()) @map("update_at")
  orderStatus String   @default("") @map("order_status")
  user        User     @relation(fields: [userId], references: [userId], onDelete: Cascade)

  @@map("personal_order")
}

model Friend {
  id          Int     @id @default(autoincrement())
  userId      Int     @map("user_id")
  friendId    Int     @map("friend_id")
  isConfirmed Boolean @default(false) @map("is_confirmed")
  user        User    @relation(fields: [userId], references: [userId], onDelete: Cascade)

  @@map("friends")
}

model File {
  id           Int    @id @default(autoincrement())
  hashName     String
  mimetype     String
  originalName String @map("original_name")
  path         String
  size         Int

  @@map("files")
}

model Subscriber {
  id        Int    @id @default(autoincrement())
  email     String
  name      String
  trainerId Int    @map("trainer_id")

  @@map("subscribers")
}

model Notify {
  id              Int      @id @default(autoincrement())
  targetUserEmail String   @map("target_user_id")
  text            String   @default("")
  createdAt       DateTime @default(now()) @map("created_at")

  @@map("notifications")
}
